I get it now. The key observation is that the best solution has the 
first,
say, x small packages and the first y big packages (in sorted order) - 
this
is obvious since a shorter package is always better than a longer one 
of the
same kind.

For x packages we do a knapsack and try to make the small van carry as 
much
as possible (not as number of packets, but as the sum of times) - so 
the
time remaining packets that the lorry must carrry is minimal.

Then we know how much time is available for the big packets and with a
binary search, or a precomputed vector (or even by a smart ordering of
packets - as in the official solution) we can find out y.

Running time: O(N*T + (N+M)*log N)
